<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('用户列表')" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
	</style>
</head>
<style>
.importTable{empty-cells:show;border-collapse:collapse;border-spacing:0;}
.listext th{background:#eee;color:#3366cc;}
.listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}

#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}
.layui-icon-more {position: absolute;right: 10px;top: 7px;cursor: pointer;}
</style>
<body class="no-skin">
<form>
	<div class="layui-form layuiadmin-card-header-auto">
		<div class="layui-form-item" th:with="fixtype=${@baseinfosimple.getFieldFrontConditions(moduleTable)}">
			<div class="layui-inline layui-col-xs3">
				<label class="layui-form-label">扩展条件：</label>
				<div class="layui-input-block">
					<select id="condition" name="condition" th:with="type=${@baseinfosimple.getFieldFrontConditions(moduleTable)}" lay-filter="fft">
						<option th:each="dict : ${type}" th:if="${dict.fields} ne 'userId' and ${dict.fields} ne 'userName' and ${dict.fields} ne 'gCName2' and ${dict.fields} ne 'stepName'"
						th:text="${dict.fieldName}" th:value="${dict.fields}" th:fft="${dict.fieldFrontType}"></option>
					</select>
				</div>
			</div>
			<div class="layui-inline layui-col-xs3" th:if="${fixdict.fieldFrontConditionsFixed} eq true" th:each="fixdict : ${fixtype}">
				<label class="layui-form-label">
				[[${fixdict.fieldName}]][[${fixdict.fieldFrontConditionsType eq 't_between' and fixdict.fieldFrontType ne 't_date' and fixdict.fieldFrontType ne 't_datetime'?'从':''}]]：</label>
				<div th:if="(${fixdict.fieldFrontType} eq 't_text') and (${fixdict.fieldFrontConditionsType} ne 't_between')" class="layui-input-block">
					<input type='text' th:name="${fixdict.fields}" th:id="${fixdict.fields}" class="layui-input search-field" autocomplete="off" fft="t_text" th:ffct="${fixdict.fieldFrontConditionsType}">
				</div>
				<div th:if="(${fixdict.fieldFrontConditionsType} eq 't_between') and ((${fixdict.fieldFrontType ne 't_date'}) and (${fixdict.fieldFrontType ne 't_datetime'}))" class="layui-input-block">
					<input type='text' th:name="${fixdict.fields}+'_s'" th:id="${fixdict.fields}+'_s'" class="layui-input search-field" autocomplete="off" fft="t_text" th:ffct="${fixdict.fieldFrontConditionsType}">
				</div>
				<div th:if="${fixdict.fieldFrontType} eq 't_date'" class="layui-input-block">
					<input type='text' th:name="${fixdict.fields}" th:id="${fixdict.fields}" class="layui-input search-field" autocomplete="off" fft="t_date" th:ffct="${fixdict.fieldFrontConditionsType}">
					<i class="dhicon dh-calendar icon_date_business" style="z-index:1"></i>
				</div>
				<div th:if="${fixdict.fieldFrontType} eq 't_datetime'" class="layui-input-block">
					<input type='text' th:name="${fixdict.fields}" th:id="${fixdict.fields}" class="layui-input search-field" autocomplete="off" fft="t_datetime" th:ffct="${fixdict.fieldFrontConditionsType}">
					<i class="dhicon dh-calendar icon_date_business" style="z-index:1"></i>
				</div>
				<div th:if="${fixdict.fieldFrontType} eq 't_checkcondition'" class="layui-input-block">
					<input type='checkbox' th:name="${fixdict.fields}" th:id="${fixdict.fields}" class="search-field" lay-skin="primary" fft="t_checkcondition" th:attr="checked=${fixdict.fieldFrontConditionsDefault ne ''?true:false}">
				</div>
				<div th:if="${fixdict.fieldFrontType} eq 't_buttontext'" class="layui-input-block">
					<input type="text" th:name="${fixdict.fields}" th:id="${fixdict.fields}" class="layui-input search-field buttontext" th:getType="${fixdict.fields}" autocomplete="off"/>
					<i class="layui-icon layui-icon-more getMore" th:onclick="getMore([[${fixdict.fields}]],null,[[${fixdict.fieldName}]],[[${fixdict.fieldSearchType}]]);" th:getType="${fixdict?.fields}"></i>
				</div>
				<div th:if="${fixdict.fieldFrontType} eq 't_dropdown'" class="layui-input-block dropdown" th:fieldName="${fixdict.fields}">
					<input type="text" th:name="${fixdict.fields}" th:id="${fixdict.fields}" class="layui-input search-field" style="position:absolute;overflow:hidden;z-index:2;width: calc(100% - 30px);" lay-verify="required" onkeyup="inputSearch()" onblur="refreshSelect()" autocomplete="off">
				</div>
				<label th:if="(${fixdict.fieldFrontConditionsType} eq 't_between') and ((${fixdict.fieldFrontType ne 't_date'}) and (${fixdict.fieldFrontType ne 't_datetime'}))" class="layui-form-label">到：</label>
				<div th:if="(${fixdict.fieldFrontConditionsType} eq 't_between') and ((${fixdict.fieldFrontType ne 't_date'}) and (${fixdict.fieldFrontType ne 't_datetime'}))" class="layui-input-block">
					<input type='text' th:name="${fixdict.fields}+'_e'" th:id="${fixdict.fields}+'_e'" class="layui-input search-field" autocomplete="off" fft="t_text" th:ffct="${fixdict.fieldFrontConditionsType}">
				</div>
			</div>
			<div class="layui-inline layui-col-md3 append-this f_r" style="margin-left:15px">
				<a class="layui-btn layuiadmin-btn-order dhicon dh-search" id="btn-search"><span class="fa_span">查询</span></a>
				<button type="reset" class="layui-btn layui-btn-primary dhicon dh-refresh" id="dh-resets"><span class="fa_span">重置</span></button>
			</div>
		</div>
	</div>
</form>
<div class="mid-content">
	<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
</div>
<div id="form_pass" style="padding:10px 60px 10px 10px;display:none;">
<form id="form-user-resetPwd" class="layui-form post_form" lay-filter="fform">
	<input type="hidden" class="userIdv" value="">
	<input type="hidden" class="upTypev" value="resetpwd">
	<div class="layui-form-item">
		<label class="layui-form-label">新密码：</label>
		<div class="layui-input-block">
		<input type="password" autocomplete="off" class="layui-input newPwdv" value="" style="width: 170px;float: left;">
		<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="saveNpw('newPwdv')" style="float: left;margin-left: 5px;margin-top: 3px;">保存</button>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">新二级密码：</label>
		<div class="layui-input-block">
		<input type="password" autocomplete="off" class="layui-input newPwdv2" value="" style="width: 170px;float: left;">
		<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="saveNpw('newPwdv2')" style="float: left;margin-left: 5px;margin-top: 3px;">保存</button>
		</div>
	</div>
</form>
</div>
<div id="form_d" style="padding:10px 60px 10px 10px;display:none;">
	<form class="post_form">
		<div id="dhtransfer" class="demo-transfer"></div>
	</form>
</div>
<!-- 用户列表导入区域 -->
<script type="text/template" id="importTpl">
<form enctype="multipart/form-data" class="mt20 mb10">
	<div class="col-xs-offset-1">
		<input type="file" id="file" name="file"/>
		<div class="mt10 pt5">
			<a onclick="$.tablelist.importTemplate('/system/user/exporttemplate')" class="btn btn-default btn-xs"><i class="dhicon dh-file-excel-o"></i> 下载模板</a>
		</div>
		<font color="red" class="pull-left mt10">
			提示：仅允许导入“xls”或“xlsx”格式文件！
		</font>
	</div>
</form>
</script>
<!-- 导入明细 -->
<div id="iTable" class="display_no">
<table class="importTable listext" data-resizable-columns-id="demo-table">
<tbody id="itbody">
</tbody>
</table>
</div>
<!-- 导入进度条 -->
<div id="importProgress" class="layui-layer-shade">
</div>
<div class="importProgress">
	<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="dhprogress">
	<div class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
	</div>
</div>
<script>
var element,thStr;
</script>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: motif-alone" />

<script th:src="@{/js/plugins/jsencrypt/jsencrypt.min.js}"></script>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" shiro:hasPermission="system:user:add">
			<i class="dhicon dh-plus"></i> 新增
		</div>
		<div class="layui-btn layui-btn-danger layui-table-tools" lay-event="deletebatch" shiro:hasPermission="system:user:delete">
			<i class="dhicon dh-remove"></i> 删除
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="importBtn" shiro:hasPermission="system:user:import">
			<i class="dhicon dh-upload"></i> 导入
		</div>
		<div class="layui-btn layui-table-tools" style="background:#5FB878" lay-event="exportbtn" shiro:hasPermission="system:user:export">
			<i class="dhicon dh-download"></i> 导出
		</div>
		<div class="layui-btn layui-table-tools" lay-event="syncWeChat" shiro:hasPermission="system:user:edit">
			<i class="dhicon dh-random"></i> 关联
		</div>
		<div class="layui-btn layui-table-tools" lay-event="onUpdateUser" shiro:hasPermission="system:user:edit">
			<i class="dhicon dh-edit"></i> 批量修改用户上级
		</div>
	</div>
</script>
<script type="text/html" id="barDh">
	{{# if(d.userLevel < "[[${session.mandatorUser.userLevel}]]" || d.userLevel == "[[${session.mandatorUser.userLevel}]]" || d.userId == "[[${session.mandatorUser.userId}]]"){ }}
	<a class="layui-btn layui-btn-xs dhicon dh-edit" lay-event="edit" shiro:hasPermission="system:user:edit" title="编辑"></a>
	<a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" lay-event="del" shiro:hasPermission="system:user:delete" title="删除"></a>
	<a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-wrench" lay-event="editpwdpost" shiro:hasPermission="system:user:edit" style="background: brown" title="重置密码"></a>
	<a class="layui-btn layui-bg-blue layui-btn-xs dhicon dh-street-view" lay-event="roleSet"  shiro:hasPermission="system:user:edit" title="分配角色"></a>
	<a class="layui-btn layui-bg-orange layui-btn-xs dhicon dh-group" lay-event="dataSet"  shiro:hasPermission="system:user:edit" title="数据权限"></a>
	<a class="layui-btn layui-bg-cyan layui-btn-xs dhicon dh-cogs" lay-event="funSet"  shiro:hasPermission="system:user:edit" title="功能权限"></a>
	{{# }else{ }}
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-edit" shiro:hasPermission="system:user:edit" title="编辑"></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-remove" shiro:hasPermission="system:user:delete" title="删除"></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-wrench" shiro:hasPermission="system:user:edit" title="重置密码"></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-street-view" shiro:hasPermission="system:user:edit" title="分配角色"></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-group" shiro:hasPermission="system:user:edit" title="数据权限"></a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-cogs" shiro:hasPermission="system:user:edit" title="功能权限"></a>
	{{# } }}
</script>
<script type="text/html" th:each="dfpl : ${gridColumns.dictionaryForPageFieldList}" th:if="${dfpl.fieldSearchType} and ${dfpl.fieldFrontType eq 't_dropdown'}" th:with="vtype=${#strings.substringAfter(#strings.substringAfter(dfpl.fieldSearchType,'_'),'_')}" th:id="'dropdown_'+${dfpl.fields}">
	<select th:name="${dfpl.fields}" th:id="${dfpl.fields}" th:with="type=${@baseinfosimple.getBaseInfoSimpleData(vtype)}">
		<option value="">请选择</option>
		<option th:each="dict : ${type}" th:text="${dict.vname}" th:value="${dict.vid}"></option>
	</select>
	</script>
<script type="text/html" id="inExchange2">
	<div class="layui-col-md12">
		<div class="layui-form-item" style="margin-top: 15px;">
			<div class="layui-inline layui-col-md4">
				<label class="layui-form-label"><span class="f_red">*</span>用户上级：</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input buttontext"
						   name="gUser3" id="gUser3" autocomplete="off"
						   readonly lay-verify="required"/>
					<i class="layui-icon layui-icon-more getMore"
					   onclick="getMore('gUserName',null,'用户上级','ts_userinfo',false, true);"
					   getType="promoteUnit"></i>
				</div>
			</div>
		</div>
	</div>
</script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var gridColumns = [[${gridColumns}]],
		importFields =[[${importFields}]],
		k_fields =[[${fields}]],
		moduleTable=[[${moduleTable}]];
	/*]]>*/
</script>
<script type="text/javascript">
var fieldWidth = {},		//导入列表字段宽度
	filedRequired = {},		//导入列表必填字段
	dateFiled = [],			//导入列表日期字段
	hasNull = false;		//导入数据必填字段有空值
var targetUserId= "",
		targetUserName='';
$.each(gridColumns.dictionaryForPageFieldList,function(i,v){
	fieldWidth[v.fields] = v.fieldFrontWidth;
	if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
	if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
})
var publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKthHRNQkJ8W3E2YVQEhXrOl6GrPIhNV8VH3BTCXqwSeetVfZNLM2bpv1AcA215xDnGmKI7f8mwW5V8Z/g4sqQkCAwEAAQ==';
//加密
function encrypt(txt) {
	const encryptor = new JSEncrypt()
	encryptor.setPublicKey(publicKey) // 设置公钥
	return encryptor.encrypt(txt) // 对数据进行加密
}
var $,layer,form,table,util,transfer,laydate,wherestr={};
layui.use(['laydate', 'table','form','layer','jquery','util', 'transfer','element'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,transfer = layui.transfer,util = layui.util, element = layui.element;
	//实例调用
	transfer.render({
		elem: '#dhtransfer'
		,data: []
		,value: []
		,title: ['未选角色', '已选角色']
		,id: 'roleSelect' //定义唯一索引
	})
	$.tablelist.init({
		elem: '#dhtable'
		,url: "/system/user/list"	
		,initSort: {field: 'userId',type: 'asc'}
		,sort:true
		,totalRow: gridColumns.totalRow
		,cols: [gridColumns.gridBody
		]
		,toolbar: '#toolbar'
		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}]
		,height:'full-96'
	});

	//头工具栏事件
	table.on('toolbar(ftable)', function(obj){
		var checkStatus = table.checkStatus('dhtable'),data = checkStatus.data,postStr = [];
		switch(obj.event){
			case 'addbtn':
				parent.layui.index.openTabsPage('/system/user/add', '用户信息 - 新增');
			break;
			case 'deletebatch':
				$.each(data,function(i,v){
					postStr.push({'userId':v.userId});
				});
				$.operate.remove('确定要删除么？','/system/user/delete',{'userInfoItems':JSON.stringify(postStr)},function(result){
					layer.closeAll();
					table.reload('dhtable', {url: "/system/user/list",page:{curr: 1}});
				});
			break;
			case 'exportbtn':
				$.ajax({
					url: '/system/user/export?deleted=0',
					type: 'GET',
					data: getWherestr(),
					dataType: 'json',
					beforeSend: function(){
						showloadings(true);
					},
					success: function(result){
						if (result.code == 0) {
							window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
							parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
						$.modal.alertWarning(result.msg)
						} else {
							$.modal.alertError(result.msg);
						}
						showloadings(false);
					}
				});
			break;
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'importBtn':
				thStr = '<tr><th><div style="width:30px;">序号</div></th>'
				$.each(importFields,function(i,val){
					fieldWidth[val] = fieldWidth[val]?fieldWidth[val]:100;			//默认宽度100px
					thStr += '<th><div style="width:'+fieldWidth[val]+'px;">' + i + '</div></th>';
				})
				thStr += '</tr>';
				layer.open({
					type: 1,
					area: ['400px', '230px'],
					fix: false,
					offset: '10%',
					maxmin: true,
					shade: 0.3,
					title: '导入用户',
					content: $('#importTpl').html(),
					btn: ['<i class="dhicon dh-check"></i> 导入', '<i class="dhicon dh-remove"></i> 取消'],
					shadeClose: true,
					zIndex: 1000,
					btn1: function(index, layero){
						var file = layero.find('#file');
						if(!file[0]['value']){
							layer.msg("请选择文件！");
							return false;
						}
						var imRes = importListExcel(file[0], importFields, 'user');
					}
				});
				break;
			case 'fieldSet':
				filedSet(moduleTable);
				break;
			case 'syncWeChat'://关联H5平台账号（企业微信 or 钉钉）
				$.modal.open(top.session.h5DeployType == 'wechat' ? '同步企业微信账号' : '同步钉钉账号', "/system/user/syncwechat",'1200','700',function(index){
					showloadings(true);
					var res = window["layui-layer-iframe" + index].callbackdata();
					var pd = [];
					$.each(res.oldData,function(i,v){
						pd.push({'userId':v.userId,'enWeChatId':''});
					})
					for(i=res.newData.length-1;i>=0;i--){
						$.each(pd,function(ii,vv){
							if(res.newData[i] && vv.userId == res.newData[i].userId){
								vv.enWeChatId=res.newData[i].enWeChatId;
								res.newData.splice(i, 1);
							}
						})
					}
					$.each(res.newData,function(i,v){
						pd.push({'userId':v.userId,'enWeChatId':v.enWeChatId});
					})
					$.post('/system/user/editpost',{'upType':"upuserbaseinfo",'userInfoItems':JSON.stringify(pd)},function(res){
						showloadings(false);
						if(res.code==0){
							setTimeout(function(){
								layer.closeAll();
								table.reload('dhtable');
							},1500)
						}
					});
				})
				break;
				case 'onUpdateUser'://批量转移用户上级
				console.log("888",data)
				if (data) {
					if (data.length < 1) {
						$.modal.msgWarning('未选中数据！');
					} else {
						layer.open({
							type: 1
							, title: "请选择用户上级"
							, shade: 0.3
							// , area: ['350px', '200px']
							, offset: '20%'
							, content: $("#inExchange2").html()
							, btn: ['确定', '取消']
							, yes: function (index) {
								if ($("#gUser3").val()) {
									$.post("/system/user/editpost", {
										'upType':"userleader",
										'userInfoItems':JSON.stringify(data),
										"targetUserId": targetUserId

									}, function (result) {
										if (result.code == 0) {
											setTimeout(function () {
												layer.closeAll();
												table.reload('dhtable');
											}, 1000);
										}
									});
								} else {
									$.modal.msgWarning('用户上级不可为空！！！');
								}
							}
							, btn2: function () {
								layer.closeAll();
							}
						});
					}
				}
				break;
		};
	});
	//监听工具条
	table.on('tool(ftable)', function (obj) {
		var data = obj.data;
		switch(obj.event){
			case 'del':
				$.operate.remove('确定要删除么？','/system/user/delete',{'userInfoItems':JSON.stringify([{'userId':data.userId}])},function(result){
					layer.closeAll();
					table.reload('dhtable', {url: "/system/user/list",page:{curr: 1}});
				});
				break;
			case 'edit':
				parent.layui.index.openTabsPage('/system/user/edit?userId='+data.userId, '用户信息-编辑');
				break;
			case 'editpwdpost':
				$(".userIdv").val(data.userId);
				$(".newPwdv").val('');
				layer.open({
					type: 1,
					area: ['420px', '180px'],
					offset: '10%',
					title: '重置密码 -【'+data.userName+ '/'+data.userId+'】',
					shade: 0.6,
					shadeClose: true,
					maxmin: true,
					content: $('#form_pass')
				}); 
				break;
			case 'roleSet':
				var roleData = [], roleSelect = [];
				$.get('/system/user/userbindrolelist?userId='+data.userId,function(data,status){
					if(data.code == 0){
						transfer.reload('roleSelect', {
							data: data.dataAll
							,value: data.dataSelect
						})
					}
				});
				layer.open({
					type: 1,
					area: ['600px', '480px'],
					offset: '10%',
					title: '分配角色 -【'+data.userName+ '/'+data.userId+'】' ,
					shade: 0.6,
					shadeClose: true,
					maxmin: true,
					content: $('#form_d'),
					btn: ['保存', '取消'],
					yes: function(index){
						var postData = transfer.getData('roleSelect'); //获取右侧数据
						var postSelectData = [];
						if(postData.length > 0){
							$.each(postData,function(i,v){
								postSelectData.push({'guid':v.value});
							})
						}
						$.operate.post('/system/user/adduserrolepost',{'userId':data.userId,'infoItems':JSON.stringify(postSelectData)},function(res){});
						layer.closeAll();
					}
				});
				break;
			case 'dataSet':
				$.modal.openFull('分配数据权限 -【'+data.userName+ '/'+data.userId+'】','/system/user/userandrolejurisdictionfordata?userId='+data.userId, function(index){
				var res = window["layui-layer-iframe" + index].callbackdata();
					$.operate.post('/system/userandrolejurisdiction/fordataeditpost',{'infoItems':JSON.stringify(res),'upType':'formodule'},function(result){
					});
				})
				break;
			case 'funSet':
				$.modal.openFull('分配功能权限 -【'+data.userName+ '/'+data.userId+'】','/system/user/userandrolejurisdictionformodule?userId='+data.userId, function(index){
					var res = window["layui-layer-iframe" + index].callbackdata();
					$.operate.post('/system/userandrolejurisdiction/formoduleeditpost',{'infoItems':JSON.stringify(res),'upType':'formodule'},function(result){
					});
				})
				break;
			case 'fieldSet':
				var mUrl = '/system/userandrolefieldstandard/userandrolefieldstandard?moduleName=ALL&moduleTable=ALL&vtype=user&fieldHidden=1&pid='+data.userId;
				$.modal.open('分配字段权限 -【'+data.userName+ '/'+data.userId+'】' , mUrl, 600, 500, function(index){
					var res = window["layui-layer-iframe" + index].callbackdata();
					var pd = [];
					$.each(res,function(i,v){pd.push({fieldStandardId: v.value,fieldStandardName: v.title})})
					$.operate.post('/system/userandrolefieldstandard/savepost',{
							'moduleName': 'ALL',
							'moduleTable': 'ALL',
							'pid': data.userId,
							'vtype': 'user',
							'fieldHidden': '1',
							'infoItems':JSON.stringify(pd)
					},function(result){
						if(result.code == 0)layer.close(index);
					});
				});
				break;
		}
	});
	//监听排序事件 
	table.on('sort(ftable)', function(obj){
		$.tablelist.sort('dhtable',obj);
	});
	form.on('switch(fdeleted)', function(data){
		if(data.elem.checked){
			$("#deleted1").val(0);
		}else{
			$("#deleted1").val(1);
		}
	})
	//搜索按钮
	$('#btn-search').on('click', function () {
		table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
	});
	//监听下拉框——添加条件
	form.on('select(fft)', function(obj){
		addMore(this);
	});
	//获取条件
	function getWherestr(){
		$(".search-field").each(function(i,v){//当前显示的查询字段(包含.search-field)
			wherestr[v.name]=''
		});
		//动态获取条件的值
		$.each(wherestr,function(i,v){
			if((i.substring(i.length-2,i.length)=='_s' || i.substring(i.length-2,i.length)=='_e') && $("#"+i).attr('fft') != 't_text'){
				if(!$("#"+i.substring(0,i.length-2)).val())wherestr[i]="";
				return;//时间控件的衍生字段需跳出循环
			}
			var vs=$("[name="+i+"]").val();
			switch($("#"+i).attr('fft')){
				case 't_checkcondition':
					if($("#"+i).prop("checked")){
						wherestr[i] = 1;
					}else{
						wherestr[i]='';
					}
				break;
				case 't_radio':
					console.log(i);
					if($("[name='"+i+"']:checked").val()){
						wherestr[i] = $("[name='"+i+"']:checked").val()
					}else{
						wherestr[i]='';
					}
					break;
				case 't_date':
					wherestr[i+'_s']="";
					wherestr[i+'_e']="";
					if($("#"+i).attr('ffct')=='t_between' && !!$("#"+i).val()){//区间范围的需要切割，而且尾头多出了空格
						var st=vs.split('~');
						wherestr[i+'_s']=st[0].substring(0,st[0].length-1);
						wherestr[i+'_e']=st[1].substring(1,st[1].length);
					}else{
						vs?wherestr[i]=vs:wherestr[i]='';
					}
					break;
				case 't_datetime':
					wherestr[i+'_s']="";
					wherestr[i+'_e']="";
					if($("#"+i).attr('ffct')=='t_between' && !!$("#"+i).val()){//区间范围的需要切割，而且尾头多出了空格
						var st=vs.split('~');
						wherestr[i+'_s']=st[0].substring(0,st[0].length-1);
						wherestr[i+'_e']=st[1].substring(1,st[1].length);
					}else{
						vs?wherestr[i]=vs:wherestr[i]='';
					}
					break;
				default:
					vs?wherestr[i]=vs:wherestr[i]='';
					break;
			}
		});
		return wherestr;
	}
})
//保存新密码
function saveNpw(cname){
	var dataObj = {userId:$(".userIdv").val(),upType:$(".upTypev").val()},
		url = '/system/user/editpwdpost';
	if($('.'+cname).val().length < 6){
		$.modal.msgError("新密码长度不能小于6位");
		return false;
	}
	if($('.'+cname).val() == $(".userIdv").val()){
		$.modal.msgError("新密码不允许设置成默认密码");
		return false;
	}
	if(cname == 'newPwdv'){
		dataObj.newPwd = encrypt($('.'+cname).val());
	}else{
		url = '/system/user/editpwd2post'
		dataObj.newPwd2 = encrypt($('.'+cname).val());
	}
	$.operate.post(url,dataObj,function(res){$('.'+cname).val('')});
}
/*批量请求导入数据
*tobj：导入数据对象
*startNum：从第几条开始导入
*oneImportNum：每次导入条数
*allImportNum：总数据量
*times：导入次数
*/
var cID = bUser = bDept = stepName = '';
function eachImport(tobj,startNum, oneImportNum, allImportNum, times, timeNum){
	var importObj = [], inum = startNum, importBl='0%', res;
	for(var i = startNum; i < startNum + oneImportNum; i++){
		if(i >= allImportNum)break;
		inum = i + 1 ;
		tobj[i]['cID'] = cID; tobj[i]['bUser'] = bUser; tobj[i]['bDept'] = bDept; tobj[i]['stepName'] = stepName;
		importObj.push(tobj[i]);
	}
	$.ajaxSettings.async = false;
	$.post("/system/user/addpost", {'userInfoItems':JSON.stringify(importObj, null, 2)}, function(result) {
		importBl = (inum/allImportNum)*100;
		console.log('导入比:'+importBl.toFixed(2)+ '%');
		console.log('数量:'+inum);
		console.log('总次数:'+times);
		console.log('当前次数:'+timeNum);
		importObj = [];
		timeNum += 1;
		res = result;
	},"json");
	setTimeout(function(){
		if(timeNum <= times){
			eachImport(tobj, startNum + oneImportNum, oneImportNum, allImportNum, times, timeNum);	
		}else{
			element.progress('dhprogress', importBl.toFixed(2)+ '%');
			showloadings(false);
			closeProcess(res, 'user');
		}
		element.progress('dhprogress', importBl.toFixed(2)+ '%');
	},500);
}
function getMoreAfter(fieldsList, fields, tindex, fieldName, fieldSearchType, isSearch, isLayer, res) {//弹出框回调事件
	// console.log('fields', fieldsList, fields, tindex, fieldName, fieldSearchType, isSearch, isLayer, res)
	console.log("res", res)
	if (res) {
		$("#gUser3").val(res.userName);
		targetUserId = res.userId
		targetUserName = res.userName
	}
}
</script>
</body>
</html>